home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Events.c
-
- Contains: A Sample application for dictionary access.
-
- Version: Technology: System 8
- Release: Daruma Developer Release 1
-
- Copyright: 1998 by Apple Computer, Inc., all rights reserved
-
- Contact: daruma@apple.com
-
- */
-
-
- #include "DictionaryAccess.h"
- #include "FunctionProto.h"
-
- #include <Menus.h>
- #include <Devices.h>
- #include <TextUtils.h>
- #include <Resources.h>
- #include <Appearance.h>
- #include <TextServices.h>
-
- // ========================================================================================
- // Global variables
- // ========================================================================================
- static Boolean gQuitNow;
-
- // ========================================================================================
- // Prototypes for static functions
- // ========================================================================================
- static void HandleMenus ( long menuResult );
- static void AdjustMenus ( void );
-
- // ========================================================================================
- // MainEventLoop
- // ========================================================================================
- void MainEventLoop ( void )
- {
- EventRecord theEvent;
- Boolean gotEvent;
- WindowPtr whichWindow;
- SInt16 partCode;
-
- gQuitNow = false;
-
- while ( true)
- {
- gotEvent = WaitNextEvent( everyEvent, &theEvent, 0L, nil);
-
- if ( gotEvent)
- {
- switch ( theEvent.what)
- {
- case mouseDown:
- partCode = FindWindow( theEvent.where, &whichWindow);
-
- switch ( partCode )
- {
- case inMenuBar:
- AdjustMenus();
- HandleMenus( MenuSelect( theEvent.where));
- break;
- default:
- break;
- }
- break;
-
- case keyDown:
- if ( theEvent.modifiers & cmdKey )
- {
- AdjustMenus();
- HandleMenus( MenuKey( theEvent.message & charCodeMask));
- }
- break;
-
- case kHighLevelEvent:
- AEProcessAppleEvent( &theEvent);
- break;
-
- case updateEvt:
- case activateEvt:
- case nullEvent:
- break;
-
- default:
- break;
- }
- }
-
- if ( gQuitNow)
- break;
- }
- }
-
-
- // ========================================================================================
- // HandleMenus
- // ========================================================================================
- static void HandleMenus ( long menuResult )
- {
- short menuID, menuItem;
- Str255 itemName;
-
- if ( menuResult == 0) return;
-
- menuID = ( ( menuResult >> 16) & 0x0000FFFF);
- menuItem = ( menuResult & 0x0000FFFF);
-
- switch ( menuID)
- {
- case kAppleMenuID:
- switch ( menuItem)
- {
- case kAboutMenuItemID:
- break;
- default:
- GetMenuItemText( GetMenuHandle( menuID), menuItem, itemName);
- OpenDeskAcc( itemName);
- break;
- }
- break;
-
- case kFileMenuID:
- switch ( menuItem)
- {
- case kOpenMenuItemID:
- DoOpenDictionaryFile();
- break;
- case kQuitMenuItemID:
- gQuitNow = true;
- break;
- default:
- break;
- }
- break;
-
- case kEditMenuID:
- break;
-
- default:
- break;
- }
-
- HiliteMenu( 0);
- }
-
-
- // ========================================================================================
- // AdjustMenus
- // ========================================================================================
- static void AdjustMenus ( void )
- {
- // Do nothing for now
- }
-
-
- // ========================================================================================
- // DoQuit
- // ========================================================================================
- static void DoQuit( void )
- {
- gQuitNow = true;
- CloseTSMAwareApplication();
- UnregisterAppearanceClient();
- }
-
-
- //========================================================================================
- // AEQuitHandler
- //========================================================================================
- pascal OSErr AEQuitHandler( AppleEvent *messagein, AppleEvent *reply, long handlerRefcon)
- {
- #pragma unused (messagein, reply, handlerRefcon)
-
- gQuitNow = true;
-
- return noErr;
- }
-
-
-
-